package com.andova;

import android.view.View;
import android.view.ViewParent;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;

import com.andova.empty.api.IEmptyApplicationOption;
import com.andova.manager.AndovaModuleManager;
import com.andova.sample.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018-03-16.
 *
 * @author kzaxil
 * @since 1.0.0
 */
class EmptyOption implements IEmptyApplicationOption, View.OnClickListener {
    @Override
    public int emptyStateLayout() {
        return R.layout.page_empty;
    }

    @Override
    public int errorStateLayout() {
        return R.layout.page_error;
    }

    @Override
    public int loadingStateLayout() {
        return R.layout.page_loading;
    }

    @Override
    public void emptyStatePage(@Nullable View view, ViewParent parent) {
        setListener(view, parent);
    }

    @Override
    public void errorStatePage(@Nullable View view, ViewParent parent) {
        setListener(view, parent);
    }

    @Override
    public void loadingStatePage(@Nullable View view, ViewParent parent) {
        setListener(view, parent);
    }

    @Override
    public List<String> filterViewClassName() {
        List<String> list = new ArrayList<>(2);
        list.add(Toolbar.class.getSimpleName());
        list.add(BottomNavigationView.class.getName());
        return list;
    }

    @Override
    public List<Integer> filterViewId() {
        return null;
    }

    private void setListener(@Nullable final View view, final ViewParent parent) {
        if (view == null) return;
        view.findViewById(R.id.btn_empty).setOnClickListener(this);
        view.findViewById(R.id.btn_error).setOnClickListener(this);
        view.findViewById(R.id.btn_loading).setOnClickListener(this);
        view.findViewById(R.id.btn_content).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_empty:
                AndovaModuleManager.obj().empty().emptyView();
                break;
            case R.id.btn_error:
                AndovaModuleManager.obj().empty().errorView();
                break;
            case R.id.btn_loading:
                AndovaModuleManager.obj().empty().loadingView();
                break;
            case R.id.btn_content:
                AndovaModuleManager.obj().empty().contentView();
                break;
        }
    }

    @Override
    public List<Class> validActivityClass() {
        List<Class> list = new ArrayList<>(1);
        list.add(EmptyStateActivity.class);
        return list;
    }
}
